package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BasePartnerContacts;
import com.sumi.erp.service.IBasePartnerContactsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 联系人Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/erp/contacts")
public class BasePartnerContactsController extends BaseController
{
    @Autowired
    private IBasePartnerContactsService basePartnerContactsService;

    /**
     * 查询联系人列表
     */
    @PreAuthorize("@ss.hasPermi('erp:contacts:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasePartnerContacts basePartnerContacts)
    {
        startPage();
        List<BasePartnerContacts> list = basePartnerContactsService.selectBasePartnerContactsList(basePartnerContacts);
        return getDataTable(list);
    }

    /**
     * 导出联系人列表
     */
    @PreAuthorize("@ss.hasPermi('erp:contacts:export')")
    @Log(title = "联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasePartnerContacts basePartnerContacts)
    {
        List<BasePartnerContacts> list = basePartnerContactsService.selectBasePartnerContactsList(basePartnerContacts);
        ExcelUtil<BasePartnerContacts> util = new ExcelUtil<BasePartnerContacts>(BasePartnerContacts.class);
        util.exportExcel(response, list, "联系人数据");
    }

    /**
     * 获取联系人详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:contacts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basePartnerContactsService.selectBasePartnerContactsById(id));
    }

    /**
     * 新增联系人
     */
    @PreAuthorize("@ss.hasPermi('erp:contacts:add')")
    @Log(title = "联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasePartnerContacts basePartnerContacts)
    {
        return toAjax(basePartnerContactsService.insertBasePartnerContacts(basePartnerContacts));
    }

    /**
     * 修改联系人
     */
    @PreAuthorize("@ss.hasPermi('erp:contacts:edit')")
    @Log(title = "联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasePartnerContacts basePartnerContacts)
    {
        return toAjax(basePartnerContactsService.updateBasePartnerContacts(basePartnerContacts));
    }

    /**
     * 删除联系人
     */
    @PreAuthorize("@ss.hasPermi('erp:contacts:remove')")
    @Log(title = "联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basePartnerContactsService.deleteBasePartnerContactsByIds(ids));
    }
}
